<template>
  <div class="cart container">
    <header>
      <i class="iconfont icon-fanhui" @click="$route.back()"></i>
      <span>购物车</span>
      <span>编辑</span>
    </header>
    <section v-if="list.length">
      <div class="cart-title" >
        <van-checkbox v-model="checked"></van-checkbox>
        <span>商品</span>
      </div>
      <ul>
        <li v-for="(item,index) in list" :key="index">
          <div class="check">
            <van-checkbox v-model="checked"></van-checkbox>
          </div>
          <h2>
            <img :src="item.goods_imgUrl" alt="">
          </h2>
          <div class="goods">
            <div class="goods-title">
              <span>{{item.goods_name}}</span>
              <i class="iconfont icon-lajitong"></i>
            </div>
            <div class="goods-price">{{item.goods_price}}</div>
            <van-stepper v-model="value" integer />
          </div>
        </li>
      </ul>
    </section>
    <section v-else>
      没有购物车数据
      <router-link to="/home">去首页逛逛把</router-link>
    </section>
    <footer v-if="list.length">
      <div class="radio">
        <van-checkbox v-model="checked"></van-checkbox>
      </div>
      <div class="total">
        <div>共有
          <span class="total-active">1</span>
          件商品</div>
        <div>
          <span>总计:</span>
          <span class="total-active">￥128.00+0茶币</span>
        </div>
      </div>
      <div class="order">去结算</div>
    </footer>
  </div>
</template>

<script>
import { mapMutations, mapState } from 'vuex';
import http from '@/common/api/request'
export default {
  name: "HomeView",
  data(){
    return{
      checked:true,
      value:1,
    }
  },
  created(){
    this.getData();
  },
  components:{
   
  },
  computed:{
    ...mapState({
      list:state=>state.cart.list
    })
  },
  methods:{
    ...mapMutations(['CART_LIST']),
    async getData(){
      let res = await http.$axios({
        url:'/api/selectCart',
        method:'post',
        headers:{
          token:true,
        },
        
      })
      console.log(res);
      this.CART_LIST(res.data)
    }
  }
};
</script>
<style lang="scss" scoped>
  header{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 1.17333rem;
    background-color: #b0352f;
    color: #fff;
    i{
      padding: 0 0.04rem;
      font-size: 0.48rem;
    }
    span{
      padding: 0,0.4rem ;
      font-size: 0.42666rem;
    }
  }
  section{
    background-color: #f5f5f5;
    .cart-title{
      display: flex;
      padding: 0.5333rem;
      span{
        padding: 0 0.4rem;
        font-size: 0.48rem;
        font-weight: 500;
      }
    }
    ul{
      display: flex;
      flex-direction: column;
      li{
        display: flex;
        text-align: center;
        justify-content: space-between;
        padding: 0.16rem 0.5333rem;
        margin: 0.21333rem 0;
        background-color: #fff;
        .check{
          padding-right: 0.3733rem;
        }
        .goods{
          display: flex;
          flex-direction: column;
          padding-left: 0.4rem;
          font-size: 0.32rem;
          .goods-title{
            display: flex;
            i{
              font-size: 0.586666rem;
            }
          }
          .goods-price{
            color: #b0352f;
            padding: 0.08rem 0;
          }
          ::v-deep .van-stepper{
            text-align: right;
          }
        }
        img{
          width: 1.97333rem;
          height: 1.97333rem;
        }
      }
    }
  }
  footer{
    display: flex;
    justify-content: space-between;
    height: 1.28rem;
    border-top: 0.05333rem solid #ccc;
    .radio{
      padding: 0 0.4rem
    }
    .total{
      flex: 1;
      font-size: 0.32rem;
      .total-active{

      }
    }
    .order{
      width: 3.2rem;
      line-height: 1.28rem;
      padding:0 0.53333rem;
      color: #fff;
      text-align: center;
      font-size: 0.42666rem;
      background-color: #b0352f;
    }
  }
</style>